//
//  HomePageViewController.m
//  厚积薄发
//
//  Created by 侯振兴 on 14/12/31.
//  Copyright (c) 2014年 侯振兴. All rights reserved.
//

#import "HomePageViewController.h"
#import "HomeController.h"
#import "ReadingRoomViewController.h"
#import "ClassificationController.h"
#import "SearchViewController.h"
#import "HoldingViewController.h"
#import "SettingsViewController.h"
#import "HomeController.h"


#define kBlueColor [UIColor colorWithRed:129/255.0 green: 198/255.0 blue: 221/255.0 alpha: 1.0]

@interface HomePageViewController ()

@end

@implementation HomePageViewController

- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"CLASSTOMAIN" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"NEWSTOUSER" object:nil];
    [[NSNotificationCenter defaultCenter] removeObserver:self name:@"USERTONEWS" object:nil];

    [_classificationNav release];
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

- (void)viewDidLoad
{



    self.view.backgroundColor = [UIColor whiteColor];
    self.navigationItem.title = @"渊虹";
    
    UIImageView *ima = [[[UIImageView alloc] initWithFrame:self.view.frame] autorelease];
    UIImage *imag = [UIImage imageNamed:@"beijing.png"];
    ima.image = imag;
    [self.view addSubview:ima];
    [self createStart];
//    [NSTimer CREATE TABLE IF NOT EXISTS lanou23(number INTEGER PRIMARY KEY AUTOINCREMENT, name TEXT, gender TEXT, age INTEGER)rt:) userInfo:nil repeats:NO];
 [NSTimer scheduledTimerWithTimeInterval:5.0f target:self selector:@selector(start:) userInfo:nil repeats:NO];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toShow) name:@"NEWSTOUSER" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toNews) name:@"USERTONEWS" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(toNews) name:@"CLASSTOMAIN" object:nil];


    
    [super viewDidLoad];
}

- (void)createStart
{
    UILabel *OLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    OLabel.tag = 1;
    OLabel.text = @"Take you enjoy the ocean of knowledge";
    OLabel.textColor = [UIColor lightGrayColor];
    OLabel.numberOfLines = 0;
    OLabel.textAlignment = NSTextAlignmentCenter;
    OLabel.font = [UIFont systemFontOfSize:50];
    [self.view addSubview:OLabel];
    [OLabel release];
    
    [UIView animateWithDuration:5.0f delay:0 options: UIViewAnimationOptionBeginFromCurrentState animations:^{
        OLabel.frame = self.view.frame;
    } completion:^(BOOL finished) {
        [self PlaylistBtnClick];
        
    }];
}


-(void)toShow
{
    [UIView animateWithDuration:1 animations:^{
        _classificationNav.view.frame = CGRectMake(-100, 0, self.view.frame.size.width, self.view.frame.size.height);
    }];
}
- (void)toNews
{
    [UIView animateWithDuration:1 animations:^{
        _classificationNav.view.frame = CGRectMake(-self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);
    }];
}


- (void)start: (NSTimer *)timer
{
    
    MSMenuView *menu=[[MSMenuView alloc]initWithFrame:CGRectMake(0, self.view.frame.size.height - 64, 0, 0)];
    [menu setDelegate:self];
    menu.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:menu];

    
//    UITabBarController *tabbar = [[[UITabBarController alloc] init] autorelease];
//    NSMutableArray *array = [NSMutableArray arrayWithObjects:homeNav, newsNav, recommendNav, collectionNav, nil];
//    tabbar.viewControllers = array;
//    [self addChildViewController:tabbar];
//    [self.view addSubview:tabbar.view];
//    tabbar.tabBar.translucent = NO;
//    tabbar.view.backgroundColor = [UIColor blackColor];
//    tabbar.view.frame = CGRectMake(self.view.frame.size.width, 0, 0, self.view.frame.size.height);
//    
//    
//    [UIView animateWithDuration:2.0f animations:^{
//        tabbar.view.frame = self.view.frame;
//    }];
//    [NSTimer scheduledTimerWithTimeInterval:2.0f target:self selector:@selector(remove:) userInfo:nil repeats:NO];
//    
}

- (void)remove:(NSTimer *)timer
{
    UILabel *Olabel = (UILabel *)[self.view viewWithTag:1];
    [Olabel removeFromSuperview];
}

-(void)PlaylistBtnClick{
    ReadingRoomViewController *readingRoom = [[[ReadingRoomViewController alloc] init] autorelease];
    UINavigationController *readingRoomNav = [[[UINavigationController alloc] initWithRootViewController:readingRoom] autorelease];
    readingRoomNav.navigationBar.translucent = NO;
    readingRoomNav.navigationBar.barTintColor = kBlueColor;
    [self addChildViewController:readingRoomNav];
    [self.view addSubview:readingRoomNav.view];
    readingRoomNav.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64);
    
    ClassificationController * classification = [[[ClassificationController alloc] init] autorelease];
    self.classificationNav = [[UINavigationController alloc] initWithRootViewController:classification];
    [self addChildViewController:_classificationNav];
    [self.view addSubview:_classificationNav.view];
    _classificationNav.view.frame = CGRectMake(-self.view.frame.size.width, 0, self.view.frame.size.width, self.view.frame.size.height);

}
-(void)ArtistBtnClick{
    SearchViewController *search = [[[SearchViewController alloc] init] autorelease];
    UINavigationController *searchNav = [[[UINavigationController alloc] initWithRootViewController:search] autorelease];
    searchNav.navigationBar.translucent = NO;
    searchNav.navigationBar.barTintColor = kBlueColor;
    [self addChildViewController:searchNav];
    [self.view addSubview:searchNav.view];
    searchNav.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64);

}
-(void)AlbumBtnClick{
    HomeController *home = [[HomeController alloc] init];
    UINavigationController *homeNav = [[[UINavigationController alloc] initWithRootViewController:home] autorelease];
    homeNav.navigationBar.translucent = NO;
    homeNav.navigationBar.barTintColor = kBlueColor;
    [self addChildViewController:homeNav];
    [self.view addSubview:homeNav.view];
    homeNav.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64);
    [home release];

}
-(void)AllSongsBtnClick{
    HoldingViewController *collection = [[[HoldingViewController alloc] init] autorelease];
    UINavigationController *collectionNav = [[[UINavigationController alloc] initWithRootViewController:collection] autorelease];
    [self addChildViewController:collectionNav];
    [self.view addSubview:collectionNav.view];
    collectionNav.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64);

}
-(void)MoreBtnClick{
    SettingsViewController *setting = [[[SettingsViewController alloc] init] autorelease];
    UINavigationController *settingNav = [[[UINavigationController alloc] initWithRootViewController:setting] autorelease];
    settingNav.navigationBar.translucent = NO;
    settingNav.navigationBar.barTintColor = kBlueColor;
//    [settingNav.navigationBar setBackgroundImage:[UIImage imageNamed:@"0.png"] forBarMetrics:UIBarMetricsDefault];
//    UILabel *newsLabel = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width - 200, 44)] autorelease];
//    newsLabel.text = @"设置";
//    newsLabel.font = [UIFont systemFontOfSize:30];
//    newsLabel.textAlignment = NSTextAlignmentCenter;
//    newsLabel.textColor = [UIColor blueColor];
//    setting.navigationItem.titleView = newsLabel;
//    settingNav.navigationItem.title = @"设置";
    [self addChildViewController:settingNav];
    [self.view addSubview:settingNav.view];
    settingNav.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64);
//    SettingsViewController *setting = [[SettingsViewController alloc] init];
//    [self.navigationController pushViewController:setting animated:YES];
}






- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
